import appApi from '@/LC/api/app';
import HoldTabbar  from 'uni-hold-tabbar'
 import {} from "vue-i18n";

import {
	defineStore
} from 'pinia';
import socket from './socket.js';
import user from './user.js';
import $router from '@/LC/router';
import homeapi from '@/LC/api/home.js';
import {
	kf
} from '../utils/kf.js';
import LC from '@/LC/index.js';

const app = defineStore({
	id: 'app',
	state: () => ({
		info: {
			default_avatar:'',
			"kefu_key": "XXXX",
			"default_lang": "zh",
			"default_forex": "USD"
		},
		cpcategory:[],
		cpcategorylist:{},
	}),
	actions: {
		// 获取Shopro应用配置和模板
		async init(templateId = null) {
			//检查网络
			// const networkStatus = await $platform.checkNetwork();
			// if (!networkStatus) {
			// 	$router.error('NetworkError');
			// }

			const userStore = user();
			if (userStore.isLogin) {
				userStore.loginAfter();
			
			}
		this.appinit()
		
		},
		async appinit(){
			const res = await homeapi.category();
			
			if (res.code === 1) {
			
				this.cpcategory = res.data
				for(let i in this.cpcategory){
					const res1 = await homeapi.category({id:this.cpcategory[i].id});
					if (res1.code === 1) {
						this.cpcategorylist[this.cpcategory[i].id]=res1.data
					}
				}
				
			}
		},
		async langs() {
			const res = await appApi.lang();

			if (res.code === 200) {

				this.lang = res.data
			}
		},
		async exchange() {
			const res = await appApi.forex();

			if (res.code === 200) {

				this.exchange_rate = res.data
			}
		}

	},
	unistorage: {
		// 初始化恢复前触发
		beforeRestore(ctx) {},
		// 初始化恢复后触发
	
	},
	
});

export default app;